package com.opgea.tutor.domain.entities;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;

import javax.persistence.CollectionTable;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.ElementCollection;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * Entity implementation class for Entity: Person
 * 
 */
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name="USER_TYPE")
public class Person implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private long id;
    private String title;
    private String firstName;
    private String middleName;
    private String lastName;
    private char sex;
    @Temporal(TemporalType.DATE)
    private Date dateOfBirth;
    @Embedded
    private Address address;

    @SuppressWarnings("rawtypes")
    @ElementCollection(targetClass = com.opgea.tutor.domain.entities.Phone.class, fetch=FetchType.LAZY)
    @CollectionTable(name = "PERSON_PHONE", joinColumns = { @JoinColumn(name = "PERSON_ID") })
    private Collection phoneNumbers;

    @SuppressWarnings("rawtypes")
    @ElementCollection(targetClass = com.opgea.tutor.domain.entities.Email.class, fetch=FetchType.LAZY)
    @CollectionTable(name = "PERSON_EMAIL", joinColumns = { @JoinColumn(name = "PERSON_ID") })
    private Collection emailIds;

    public Person() {
	super();
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getTitle() {
	return title;
    }

    public void setTitle(String title) {
	this.title = title;
    }

    public String getFirstName() {
	return firstName;
    }

    public void setFirstName(String firstName) {
	this.firstName = firstName;
    }

    public String getMiddleName() {
	return middleName;
    }

    public void setMiddleName(String middleName) {
	this.middleName = middleName;
    }

    public String getLastName() {
	return lastName;
    }

    public void setLastName(String lastName) {
	this.lastName = lastName;
    }

    public char getSex() {
	return sex;
    }

    public void setSex(char sex) {
	this.sex = sex;
    }

    public Date getDateOfBirth() {
	return dateOfBirth;
    }

    public void setDateOfBirth(Date dateOfBirth) {
	this.dateOfBirth = dateOfBirth;
    }

    @SuppressWarnings("rawtypes")
    public Collection getPhoneNumbers() {
	return phoneNumbers;
    }

    @SuppressWarnings("rawtypes")
    public void setPhoneNumbers(Collection phoneNumbers) {
	this.phoneNumbers = phoneNumbers;
    }

    @SuppressWarnings("rawtypes")
    public Collection getEmailIds() {
	return emailIds;
    }

    @SuppressWarnings("rawtypes")
    public void setEmailIds(Collection emailIds) {
	this.emailIds = emailIds;
    }

    public Address getAddress() {
        return address;
    }

    public void setAddress(Address address) {
        this.address = address;
    }

    @Override
    public String toString() {
	return "Person [title=" + title + ", firstName=" + firstName
		+ ", middleName=" + middleName + ", lastName=" + lastName
		+ ", sex=" + sex + ", dateOfBirth=" + dateOfBirth
		+ ", phoneNumbers=" + phoneNumbers + ", emailIds=" + emailIds
		+ ", address=" + address + "]";
    }

}
